package com.wenchao.quickstart.utils;


import java.math.BigDecimal;

public class MoneyUtil {

    private MoneyUtil() {
    }

    public static String formatMoney(String old) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }

    public static String formatMoney(double old) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }

    public static double formatMoney2Double(double old) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static double formatMoney2Double(String old) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue();
    }

    public static String formatMoney(int old) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(2, BigDecimal.ROUND_HALF_UP).toString();
    }

    public static String formatMoney(String old, int length) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(length, BigDecimal.ROUND_HALF_UP).toString();
    }

    public static String formatMoney(double old, int length) {
        BigDecimal bigDecimal = new BigDecimal(old);
        return bigDecimal.setScale(length, BigDecimal.ROUND_HALF_UP).toString();
    }

}
